package leetcode;

/**
 * 543. 二叉树的直径
 */
public class Solution543 {
    int maxDepth = 0;
    public int diameterOfBinaryTree(TreeNode root) {
        maxDepth(root);
        return maxDepth;
    }
    public int maxDepth(TreeNode root){
        if(root == null){
            return 0;
        }
        int left = maxDepth(root.left);
        int right= maxDepth(root.right);
        maxDepth = Math.max(left + right,maxDepth);
        return 1+Math.max(left,right);
    }
}
